<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    let colors =
      [{
        house: '0',
        color: 'blue'
      },
      {
        house: '1',
        color: 'blue'
      },
      {
        house: '2',
        color: 'blue'
      },
      {
        house: '3',
        color: 'red'
      },
      {
        house: '4',
        color: 'red'
      }
      ]
    const n = colors.length
    let max = 0
    for (let i = 0; i < n - 1; i++) {
      for (let j = i + 1; j < n; j++) {
        let dis = Math.abs(i - j) //函数的绝对值
        if (colors[i].color !== colors[j].color) {
          max = Math.max(max, dis)
        }
      }
    }
    console.log(max);
  </script>
</body>

</html>